package com.badcat.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.Date;

/**
 * @author ：badcat
 * @date ：Created in 2022/6/25 17:11
 * @description ：
 */
@RestController
@RequestMapping("/formDataProgress")
public class FormDataProgressController {

    private final String path = "D:\\study\\project\\2022study\\gitee\\file_upload\\formDataProgress";

    @PostMapping("/upload")
    public String upload(MultipartFile file) throws Exception{
        String contentType = file.getContentType();
        String name = file.getName();
        String originalFilename = file.getOriginalFilename();
        System.err.println(contentType);
        System.err.println(name);
        System.err.println(originalFilename);

        File fileDirectory = new File(path);
        if (!fileDirectory.exists()){
            fileDirectory.mkdirs();
        }

        file.transferTo(new File(path + "\\" + new Date().getTime() + "_" + originalFilename));

        return "ok";
    }

    @PostMapping("/test")
    public String test(){
        return "test";
    }
}
